<?php

namespace App\Http\Controllers\PC\User;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Service\User\UserService;
use App\Http\Controllers\Controller;

use App\Http\Service\Statistic\StatisticService;
use Session;
use Config;


class RegisterController extends Controller
{
    protected $index = 'PC.User.register';
    private $statistic;
    private $params = [];

    public function __construct(StatisticService $statistic)
    {
        $this->statistic = new StatisticService();
    }
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * 注册视图
     */
    public function register()
    {
        $title='注册';
        return view($this->index)->with('title',$title);
   }

    /**
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Laravel\Lumen\Http\Redirector|void
     * 执行注册
     */
    public function doRegister(Request $request)
    {
        $data = [];
        $data['name'] = $request->input('username');
        $data['password'] = $request->input('password');
        $data['mobile'] = $request->input('mobile');
        $data['verify_code'] = $request->input('code');
        $data['agent_id'] = env('AGENT');
        $user = new UserService();
        $ret = $user->register($data);
        try{
            if(Session::get(Config::get('custom.setting.MEMBER_QUERY')))
            {
                $this->params['url'] = Session::get(Config::get('custom.setting.MEMBER_QUERY'));
                $this->params['code'] = Session::get(Config::get('custom.setting.MEMBER_UNQUIE_CODE'));

                $this->params['action'] = 'register';    // 注册
                $this->params['terminal_id'] = 2;  //  PC端
                $this->params['status'] = '1';  //  PC端
                $this->params['ip'] = $request->getClientIp();  //  客户端IP
                $this->statistic->Statictis($this->params);
            }

        }catch (\Exception $exception){

        }

        return $ret;
    }
}
